<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('报关单')" />
    <th:block th:include="include :: list-css" />
    <style type="text/css">
        .layui-tab-title{border-color: #ccc !important;}
        .layui-this{color: rgb(0, 135, 250) !important;background: none !important;}
        .layui-tab-brief > .layui-tab-title .layui-this:after, .layui-tab-brief > .layui-tab-more li.layui-this:after{border-color:  rgb(0, 135, 250) !important;}
        label.layui-form-label {width: 95px;padding-right: 0px;}
        .layui-form-radio {margin-top:0}
        .mid-content{overflow-y:auto}
        .importTable{empty-cells:show;border-collapse:collapse;border-spacing:0;}
        .listext th{background:#eee;color:#3366cc;}
        .listext th,.listext td{border:solid 1px #ddd;text-align:left;padding:10px;font-size:14px;}
        #importProgress {z-index:20200202;background-color: #000;opacity: 0.3;display:none;}
        .importProgress {width:300px;z-index:20202222;position: fixed;top: 34%;left: 40%;display:none;}
    </style>
</head>
<body>
<div class="main-content">
    <div class="content-right">
        <div class="search-top">
            <span>查询条件</span>
            <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
                <i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
            </a>
        </div>
        <div class="panel layout-expand layui-expand-east">
            <div class="panel-header">
                <div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
                    <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
                        <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
                    </a>
                </div>
            </div>
            <div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
        </div>
        <form class="layui-form">
            <th:block th:include="listinclude :: searchRight('page')" />
        </form>
    </div>
    <div class="mid-content">
        <div class="layui-tab layui-tab-brief istype" lay-filter="demo1" style="margin-top: 0;">
            <ul class="layui-tab-title" >
                <li class="layui-this">处理中</li>
                <li>已完成</li>
            </ul>
            <div class="layui-tab-content"></div>
        </div>
        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
    </div>
</div>
<!-- 表格头部工作栏-->
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <span class="ishide">
          <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn" >
            <i class="dhicon dh-lujing1089"></i> 新增
         </div>
         <div class="layui-btn layui-table-tools importbtn-bg shbtn" lay-event="shbtn" >
                <i class="dhicon layui-icon-prev"></i> 审核
        </div>
         <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="exportbtn" >
            <i class="dhicon dh-zu4250_2_2"></i> 导出
         </div>
        </span>
        <span class="iszx" style="display: none;">
			<div class="layui-btn layui-table-tools importbtn-bg htbtn" lay-event="htbtn" >
                <i class="dhicon layui-icon-prev"></i> 回退
            </div>
			 <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="exportbtn">
            	<i class="dhicon dh-zu4250_2_2"></i> 导出
        	 </div>
             <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="exportbtn2">
            	<i class="dhicon dh-zu4250_2_2"></i> 报关单导出
        	 </div>
            <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="bgFilesDefaultUpload">
                <i class="layui-icon layui-icon-upload getUpload"></i> 报关单附件
        	 </div>
            <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="cgFilesDefaultUpload">
                <i class="layui-icon layui-icon-upload getUpload"></i> 采购发票附件
        	 </div>
	    </span>
    </div>
</script>

<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: searchJS" />
<th:block th:include="listinclude :: list-templeat" />
<script th:src="@{/dhecp/js/queryCondition.js}"></script>
<script th:inline="javascript">
    var gridColumns = [[${gridColumns}]],
        storage = [[${storage}]],
        buttonState = [[${buttonState}]],
        businessName = gridColumns.moduleAlias,
        passwordAuthentication = [[${passwordAuthentication}]],
        moduleTable = [[${moduleTable}]],
        importFields =[[${importFields}]];
    var prefix = "/storage/"+storage;
    var tableUrl = prefix + "/list";
    exportUrl = prefix + "/export";
    var num = 0;
</script>

<script type="text/javascript">
    var element,thStr;
    var fieldWidth = {},		//导入列表字段宽度
        filedRequired = {},		//导入列表必填字段
        dateFiled = [],			//导入列表日期字段
        hasNull = false;		//导入数据必填字段有空值
    $.each(gridColumns.dictionaryForPageFieldList,function(i,v){
        fieldWidth[v.fields] = v.fieldFrontWidth
        if(v.fieldFrontRequired)filedRequired[v.fields] = v.fieldName;
        if(v.fieldFrontType == 't_date')dateFiled.push(v.fields);
    })

    var $,layer,laydate,form,table,wherestr={};
    layui.use(['table','laydate','form','layer','jquery','element'], function () {
        $ = layui.$, layer = layui.layer,laydate = layui.laydate , form = layui.form, table = layui.table, element = layui.element;
        serachRender();//查询条件初始渲染集合
        changeDropdown('fSl');//导入窗口——税率下拉可编辑赋事件
        $.tablelist.init({
            elem: '#dhtable'
            ,modalName: "产品信息"
            ,url: tableUrl
            ,updateUrl: prefix + "/edit?guid={id}"
            ,initSort: {field: 'createTime',type: 'asc'}
            ,totalRow: gridColumns.totalRow
            ,cols: [gridColumns.gridBody]
            ,toolbar: '#toolbar'
            ,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
            ,parseData: function(res){ //res 即为原始返回的数据
                var objpage=sessionStorage.getItem(moduleTable+'checkdata')
                if(objpage){
                    objpage=JSON.parse(objpage)
                    res.data.map((v,i)=>{
                        objpage.map((n,m)=>{
                            if(v.guid==n.guid){
                                v.LAY_CHECKED=true
                            }
                        })
                    })
                }
            }
            ,done:function(res, curr, count){
                var ltv=this.elem.next('.layui-table-view');//当前table的dom
                res.data.length || count || ltv.find('.layui-table-header').css('display', 'inline-block');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
                res.data.length || count || ltv.find('.layui-table-box').css('overflow-x', 'auto');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
                $('.layui-table-body').eq(0).css('height', "75vh");
                fixTotal(this);//修复合计行固定列问题
                rowheight(res, curr);//修复合计行固定列问题
                if(typeof listTableDone == 'function')listTableDone();//如果查询列表存在表格加载完成回调事件，则执行
            }
        });
        //监听排序事件
        table.on('sort(ftable)', function(obj){
            $.tablelist.sort('dhtable',obj);
        });

        // 多选赋值
        sessionStorage.setItem(moduleTable+'checkdata','')
        table.on('checkbox(ftable)', function(obj){
            var objpage=sessionStorage.getItem(moduleTable+'checkdata')
            if(obj.type=='all'){//判断是否全选
                var objdata=table.checkStatus('dhtable')
                objdata=objdata.data
                if(obj.checked){//判断是否选中
                    if(objpage){
                        objpage=JSON.parse(objpage)
                        objpage=objpage.concat(objdata)
                        objpage=newData(objpage)
                    }else{
                        objpage=objdata
                    }
                }else{
                    var objpage=JSON.parse(objpage)
                    var deldata=table.cache.dhtable
                    objpage=delData(objpage,deldata)
                }
                sessionStorage.setItem(moduleTable+'checkdata',JSON.stringify(objpage))
            }else{//点击复选框
                if(objpage){
                    objpage=JSON.parse(objpage)
                    if(obj.checked){
                        objpage.push(obj.data)
                    }else{
                        objpage.map((v,i)=>{
                            if(v.guid==obj.data.guid){
                                objpage.splice(i,1)
                            }
                        })
                    }
                }else{
                    objpage=[]
                    objpage.push(obj.data)
                }
                sessionStorage.setItem(moduleTable+'checkdata',JSON.stringify(objpage))
            }
        });

        // 头部组装切换
        element.on('tab(demo1)', function(elem){
            moduleTable = "TS_CustomsClearance";
            var tableUrl1 = "";
            switch(elem.index){
                case 0://处理中
                    tableUrl1 = prefix+"/list?type="+0
                    break;
                case 1://已完成
                    tableUrl1 = prefix+"/list?type="+1
                    break;
            };

            $.tablelist.init({
                elem: '#dhtable'
                ,url: tableUrl1
                ,totalRow: gridColumns.totalRow
                ,cols: [gridColumns.gridBody]
                , toolbar: '#toolbar'
                , defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
                , done: function (res, curr, count) {
                    listData1 = table.cache.dhtable;//每次重载都赋值更新表缓存
                    if(elem.index == 0){
                        $('.ishide').show()
                        $('.iszx').hide()
                    }else if(elem.index == 1){
                        $('.ishide').hide()
                        $('.iszx').show()
                    }
                    $('.layui-table-body').eq(0).css('height', "75vh");
                    sessionStorage.setItem(moduleTable+'checkdata','')
                },success:function(a,b,c){
                    console.log(a,b,c)
                }
            });
            // var cephalosome = document.getElementById("cephalosome");//获取所有的table
            // var str = queryCondition(data.fixtype);
            // cephalosome.innerHTML = str;
            form.render();
            $('#btn-search').unbind()
            serachRender()
            setTimeout(() => {firstimg()}, 1000);
        });


        //监听行双击事件
        table.on('rowDouble(ftable)', function (obj) {
            if (typeof buttonState == 'object' && buttonState['list-add'] !== 'hidden') parent.layui.index.openTabsPage(prefix+ "/edit?nid="+obj.data.nid, "报关单" + '(' + obj.data.bid + ')');
        })

        //头工具栏事件
        table.on('toolbar(ftable)', function(obj){
            switch(obj.event){
                case 'addbtn'://新增
                    parent.layui.index.openTabsPage(prefix+'/edit', '报关单 - 新增');
                    break;
                case 'shbtn'://审核
                    var objpage=sessionStorage.getItem(moduleTable+'checkdata')
                    if(!objpage || objpage == '[]'){
                        layer.msg("请先选择数据！");
                    }else{
                        $.modal.confirmCom('确定要审核么？',function(result){
                            var infoItems=JSON.parse(objpage)
                            if (infoItems.some(item => item.effectStock == false)) {
                                layer.msg("选择单据有制单状态,请核实后在操作!");
                                return;
                            }
                            if (infoItems.some(item => item.state != '无')) {
                                layer.msg("选择单据状态已变动,请核实后在操作!");
                                return;
                            }
                            showloadings(true);
                            $.operate.post(prefix+"/shbtn?type=0",{infoItems:JSON.stringify(infoItems)},function(res){
                                if(res.code == 0){
                                    setTimeout(function(){
                                        sessionStorage.setItem(moduleTable+'checkdata','')
                                        layer.closeAll();
                                        showloadings(false);
                                        table.reload('dhtable', {page: {curr: 1},where:getWherestr()});
                                    }, 1000);
                                } else{
                                    showloadings(false);
                                }
                            });
                        })
                    }
                    break;
                case 'htbtn'://回退
                    var objpage=sessionStorage.getItem(moduleTable+'checkdata')
                    if(!objpage || objpage == '[]'){
                        layer.msg("请先选择数据！");
                    }else{
                        $.modal.confirmCom('确定要回退么？',function(result){
                            var infoItems=JSON.parse(objpage)
                            if (infoItems.some(item => item.state == '无' || item.state == '已完成')) {
                                layer.msg("选择单据状态不允许回退,请核实后在操作!");
                                return;
                            }
                            showloadings(true);
                            $.operate.post(prefix+"/shbtn?type=1",{infoItems:JSON.stringify(infoItems)},function(res){
                                if(res.code == 0){
                                    setTimeout(function(){
                                        sessionStorage.setItem(moduleTable+'checkdata','')
                                        layer.closeAll();
                                        showloadings(false);
                                        table.reload('dhtable', {page: {curr: 1},where:getWherestr()});
                                    }, 1000);
                                } else{
                                    showloadings(false);
                                }
                            });
                        })
                    }
                    break;
                case "exportbtn"://导出
                    $.ajax({
                        url: prefix+'/export',
                        type: 'GET',
                        data: getWherestr(),
                        dataType: 'json',
                        beforeSend: function () {
                            showloadings(true);
                        },
                        success: function (result) {
                            if (result.code == 0) {
                                window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
                                parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
                            } else if (result.code == web_status.WARNING) {
                                $.modal.alertWarning(result.msg)
                            } else {
                                $.modal.alertError(result.msg);
                            }
                            showloadings(false);
                        }
                    });
                    break;
                case 'fieldSet':
                    filedSet(moduleTable);
                    break;
                case 'bgFilesDefaultUpload':
                    var objpage=sessionStorage.getItem(moduleTable+'checkdata')
                    if(!objpage || objpage == '[]') {
                        layer.msg("请先选择数据！");
                    }else {
                        var infoItems=JSON.parse(objpage);
                        if(infoItems.length > 1) {
                            layer.msg("只允许选择一条数据,请核实后在操作！");
                            return;
                        }else {
                            if (infoItems.some(item => item.derivedstate == '无')) {
                                layer.msg("选择单据状态未报关导出,请核实后在操作!");
                                return;
                            }
                            getUploadCommon("bgFilesDefault", "Head", infoItems[0].guid);
                        }
                    }
                    break;
                case 'cgFilesDefaultUpload':
                    var objpage=sessionStorage.getItem(moduleTable+'checkdata')
                    if(!objpage || objpage == '[]') {
                        layer.msg("请先选择数据！");
                    }else {
                        var infoItems=JSON.parse(objpage);
                        if(infoItems.length > 1) {
                            layer.msg("只允许选择一条数据,请核实后在操作！");
                            return;
                        }else {
                            if (infoItems.some(item => item.derivedstate == '无')) {
                                layer.msg("选择单据状态未报关导出,请核实后在操作!");
                                return;
                            }
                            getUploadCommon("cgFilesDefault", "Head", infoItems[0].guid);
                        }
                    }
                    break;
                case 'exportbtn2':
                    var objpage=sessionStorage.getItem(moduleTable+'checkdata')
                    if(!objpage || objpage == '[]') {
                        layer.msg("请先选择数据！");
                    }else {
                        var infoItems = JSON.parse(objpage);
                        if (infoItems.length > 1) {
                            layer.msg("只允许选择一条数据,请核实后在操作！");
                            return;
                        } else {
                            $.ajax({
                                url: prefix+'/export2?bid='+infoItems[0].bid,
                                type: 'GET',
                                data: getWherestr(),
                                dataType: 'json',
                                beforeSend: function () {
                                    showloadings(true);
                                },
                                success: function (result) {
                                    if (result.code == 0) {
                                        window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
                                        parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
                                    } else if (result.code == web_status.WARNING) {
                                        $.modal.alertWarning(result.msg)
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                    showloadings(false);
                                }
                            });
                        }
                    }
                    break;
            }
        });
    });

</script>
</body>
</html>